<template>
<div>

  <h3>请输入分数:</h3>
  <el-form ref="scoreForm" style="margin: 20px 10px;width: 100%" :model="scoreForm"  size="default" :rules="rules">

    <el-form-item prop="score" >
      <el-input  v-model="scoreForm.score"></el-input>
    </el-form-item>
    <el-form-item style="width: 100%" >

      <el-button style="margin-left: 150px" size="large" @click="returnScore">提交</el-button>
    </el-form-item>


  </el-form>
</div>
</template>

<script>
import request from "@/utils/request";
import {ElMessage} from "element-plus";

export default {
  setup(){
return{

}
  },
  name: "single",
  props:{
    idx: {
      type: Number,
      default:-1
    },
  },
  created() {
    this.user=JSON.parse(localStorage.getItem("user"))
    this.scoreForm.gameId=JSON.parse(sessionStorage.getItem("gameId"))
  },
  data(){
    return{
      user:{},
      scoreForm:{
        score:"",
        judgeId:"",
        itemId:""
      },
      rules:{
        score: [
          {required:true,message:"请输入分数",trigger:"blur"},
        ],

      }
    }
  },
  methods:{

    returnScore(){
      this.$refs['scoreForm'].validate((valid) =>{
        if (valid){
          if(this.scoreForm.score<0 || this.scoreForm.score>100){
            this.$message.error("分数输入错误")
            return;
          }


          request.post("/score/returnScore",this.scoreForm).then(res =>{
            // console.log(res)
            if (res.code === 200) {
              ElMessage({
                type: "success",
                message: "提交成功"
              })
            } else {
              ElMessage({
                type: "error",
                message: "提交失败"
              })
            }
          })
        }else{
          return false;
        }
      })
      this.scoreForm.judgeId=this.user.id
      this.scoreForm.itemId=this.idx
      // console.log(this.scoreForm)
      // console.log(this.idx)


    },
  }
}
</script>

<style scoped>

</style>